
function onClickEdit(elem)
{
  if (elem.tagName != "TD") return;
  if (elem.firstChild && elem.firstChild.tagName == "INPUT") return;
  
  prevText = elem.innerHTML;
  elem.innerHTML = ""; 

  var inputBox = document.createElement("INPUT");
  inputBox.style.width = "100%";
  inputBox.style.textAlign = "right";
  inputBox.type = "text";
//  inputBox.value = "" + escape(prevText);
  inputBox.value = "" + prevText;
  inputBox.addEventListener('blur', lostFocus, false);
  inputBox.addEventListener('keypress', testEnter, false);
  elem.appendChild(inputBox);
  inputBox.select();
}


function testEnter(e)
{
  if (e.keyCode == 13) lostFocus(e);
}

function lostFocus(e)
{
  var elem = e.srcElement ? e.srcElement : e.target; 
  elem.parentNode.innerHTML = elem.value;

  var sr = document.getElementById('searchResults'); //TODO(carterm) - remove hardcoded elem id
  var evt = document.createEvent("Events");
  evt.initEvent("change", true, false);
  sr.dispatchEvent(evt);
}
